package sixteen;

/**
 * @author zzb
 * @since 2021-01-14
 */

//ConcreteIterator
public class IteratorImpl implements Iterator{
  private List list;
  private int index;

  public IteratorImpl(List list) {
    this.index = 0;
    this.list = list;
  }

  @Override
  public Object next() {
    Object obj = list.get(index);
    index++;
    return obj;
  }

  @Override
  public void first() {
    this.index = 0;
  }

  @Override
  public void last() {
    this.index = list.getSize();
  }

  @Override
  public boolean hasNext() {
    return index < list.getSize();
  }
}
